//
//  NTESLiveroomSelectViewController.m
//  Netease
//
//  Created by 王方伟 on 2017/8/31.
//  Copyright © 2017年 wfw. All rights reserved.
//

#import "NTESLiveroomSelectViewController.h"
#import "SHAnchorPreviewController.h"
#import "NTESLiveManager.h"
#import "NTESDemoService.h"
#import "SHDragView.h"
#import <NIMAVChat/NIMAVChat.h>

@interface NTESLiveroomSelectViewController ()
@property (weak, nonatomic) IBOutlet UITextField *roomF;

@end

@implementation NTESLiveroomSelectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark 设置导航栏
- (void)setupNavigation{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"娱乐直播";
}

- (IBAction)onClickButton:(UIButton *)sender {
    [SVProgressHUD showMessage:@"加载中..."];
    __weak typeof(self) weakSelf = self;
    [[NTESDemoService sharedService] requestPlayStream:_roomF.text completion:^(NSError *error, NSString *playStreamUrl,NTESLiveType liveType,NIMVideoOrientation orientation) {
        [SVProgressHUD dismiss];
        if (!error) {
            [NTESLiveManager sharedLiveManager].orientation = orientation;
            [NTESLiveManager sharedLiveManager].type = liveType;
            [NTESLiveManager sharedLiveManager].role = NTESLiveRoleAudience;
            [NTESLiveManager sharedLiveManager].chatroomId = weakSelf.roomF.text;
            [NTESLiveManager sharedLiveManager].streamUrl = playStreamUrl;
            SHDragView *dragView = (SHDragView *)[weakSelf.view drageView];
            if (dragView) {
                if (dragView.isBig) return;
                SHAnchorPreviewController *anchorPreVC = [[SHAnchorPreviewController alloc] init];
                [DCURLRouter presentViewController:anchorPreVC animated:YES completion:^{
                    dragView.isBig = YES;
                }];
            }else{
                SHAnchorPreviewController *anchorPreVC = [[SHAnchorPreviewController alloc] init];
                [DCURLRouter presentViewController:anchorPreVC animated:YES completion:nil];
            }
        }else{
            [SVProgressHUD showInfo:@"进入直播失败"];
        }
    }];
}


@end
